function [sub_x, sample_y] = JADE(sub_x, sample_y, best_x, index1, maxIteration,dim, LB, UB, Fun)

muCR = 0.5;    % 相关变量的初始化
muF = 0.5;
A = [];
%p = 1 / 3;      % 取最好的那一个
c = 0.2;
popsize = size(sub_x,1);

for time = 1 : maxIteration
    SF = [];
    SCR = [];
    for i = 1 : popsize

        CR = normrnd(muCR, 0.1);    % 正太随机数 
        F = Cauchy_rand(muF, 0.1);    % 柯西随机数
        [~, sortIndex] = sort(sample_y);    % 随机选择前 popsize * p 对应的 xPBest
        sortSol = sub_x(sortIndex, :);
        % xPBest = sortSol(randi(p * popsize), :);
        xPBest = sortSol(1, :);

        r1 = randi(popsize);
        while r1 == i
            r1 = randi(popsize);
        end
        SolA = [sub_x; A];
        r2 = randi(size(SolA, 1));
        while r2 == r1 || r2 == i
            r2 = randi(size(SolA, 1));
        end
        mutantPos = sub_x(i, :) + F * (xPBest - sub_x(i, :)) + F * (sub_x(r1, :) - SolA(r2, :));    % 突变

        jj = randi(dim);  % 选择至少一维发生交叉
        for d = 1:dim
            if rand() < CR || d == jj
                crossoverPos(d) = mutantPos(d);
            else
                crossoverPos(d) = sub_x(i,d);
            end
        end

        crossoverPos(crossoverPos>UB) = UB;     % 检查是否越界
        crossoverPos(crossoverPos<LB) = LB;
        best_x(:,index1) = crossoverPos;
        evalNewPos = Fun(best_x);    % 将突变和交叉后的变量重新评估
        if evalNewPos < sample_y(i)    % 小于原有值就更新
            A = [A; sub_x(i,:)];
            if size(A, 1) > popsize
                A(randi(size(A, 1)), :) = [];    % 保持A的数目不超过popsize
            end
            SCR = [SCR; CR];
            SF = [SF; F];
            sub_x(i,:) = crossoverPos;
            sample_y(i) = evalNewPos;
        end
    end
    muCR = (1 - c) * muCR + c * mean(SCR);
    muF = (1 - c) * muF + c * (sum(SF .* SF) / sum(SF));
end
end